package com.jzg.jcptadmin.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jzg.jcptadmin.R;


/**
 * author: guochen
 * date: 2016/8/18 18:59
 * email:
 */
public class MyErrorLayout extends RelativeLayout implements View.OnClickListener {

    private ImageView errorImage;
    private TextView errorText;
    private Button errorBtn;

    public MyErrorLayout(Context context) {
        this(context, null);
    }

    public MyErrorLayout(Context context, AttributeSet attrs) {
        this(context, attrs, 0);

    }

    public MyErrorLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        View view = LayoutInflater.from(context).inflate(R.layout.errou_layout, this, true);
        errorImage = (ImageView) view.findViewById(R.id.iv_error);
        errorText = (TextView) view.findViewById(R.id.tv_error);
        errorBtn = (Button) view.findViewById(R.id.bt_errorbtn);
        errorBtn.setOnClickListener(this);
        this.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }

    public Button getErrorButtonView() {

        return errorBtn;
    }

    public TextView getErrorTextView() {

        return errorText;
    }

    public ImageView geteErrorImageView() {
        return errorImage;
    }

    public ReloadClickLintener reloadClickLintener;

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.bt_errorbtn:
                    if(reloadClickLintener!=null){
                        reloadClickLintener.onReload();
                    }
                break;
            default:

                break;
        }
    }

    public interface ReloadClickLintener{
             void onReload();
    }

    public void setOnReloadClickLintener(ReloadClickLintener reloadClickLintener){
        this.reloadClickLintener = reloadClickLintener;
    }

    @Override
    public boolean onInterceptHoverEvent(MotionEvent event) {
        return true;
    }
}
